package com.icss.lesson5;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class TestMain1 {
    public static void main(String[] args) {

        Set<String> set = new HashSet<>();

        set.add("中国");
        set.add("印度");
        set.add("日本");
        set.add("韩国");
        System.out.println(set.add("日本")); // false
        System.out.println(set.size());

        set.forEach(System.out::println);
        System.out.println("----------------------------");
        Set<Country> set2 = new HashSet<>();

        set2.add(new Country("中国"));
        set2.add(new Country("印度"));
        set2.add(new Country("日本"));
        set2.add(new Country("韩国"));

        // Country 覆盖 hashcode和equals 定义了 去重规则
        System.out.println(set2.add(new Country("韩国"))); //
        System.out.println(set2.size());
        set2.forEach(System.out::println);


    }
}
